//
// Created on 2024/3/18.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef OHOS_WEBVIEWHANDLER_H
#define OHOS_WEBVIEWHANDLER_H
#include "napi/editbox/TextComponentsInfo.h"
#include "napi/editbox/TextInfoMap.h"
#include "napi/helper/NapiHelper.h"
class WebviewHandler{
    public:
        /**--------------------webview callback回调-----------------------**/
        virtual void onShouldStartLoadingEvent(int32_t id, const char * url) = 0;
        virtual void onFinishLoadingEvent(int32_t id, const char * url) = 0;
        virtual void onFailLoadingEvent(int32_t id, const char * url) = 0;
        virtual void onJsCallbackEvent(int32_t id, const char *url) = 0;

        /**--------------------webview 相关API-----------------------**/
        void createWebView(int32_t id,int32_t x,int32_t y,int32_t w,int32_t h) {
            JSFunction::getFunction("WebView.createWebView").invoke<void>(id, x, y, w, h);
        }
        void setWebViewRect(int32_t id, int32_t x, int32_t y, int32_t w, int32_t h) {
            JSFunction::getFunction("WebView.setWebViewRect").invoke<void>(id, x, y, w, h);
        }

        void loadFromFile(int32_t id,const char* filePath) { JSFunction::getFunction("WebView.loadFile").invoke<void>(id, filePath); }
        void loadFromUrl(int32_t id, const char *url) {
            JSFunction::getFunction("WebView.loadURL").invoke<void>(id, url);
        }

        void stopLoading(int32_t id) { JSFunction::getFunction("WebView.stopLoading").invoke<void>(id); }

        void goBack(int32_t id) { JSFunction::getFunction("WebView.goBack").invoke<void>(id); }
        void goForward(int32_t id) { JSFunction::getFunction("WebView.goForward").invoke<void>(id); }
        void removeWebView(int32_t id) { JSFunction::getFunction("WebView.removeWebView").invoke<void>(id); }
        void deleteCookie(int32_t id) { JSFunction::getFunction("WebView.deleteCookie").invoke<void>(id); }
        void reload(int32_t id) { JSFunction::getFunction("WebView.reload").invoke<void>(id); }
        static  WebviewHandler* getInstance(){
            return instance;
        }
    protected:
        static WebviewHandler* instance;
};
#endif //OHOS_WEBVIEWHANDLER_H
